# Read files
R1_RT <- read.table("r1rt.csv", header=TRUE)
R1_No <- read.table("r1no.csv", header=TRUE)
R2_RT <- read.table("r2rt.csv", header=TRUE)
R2_No <- read.table("r2no.csv", header=TRUE)
# Define max values
maxLatency <- max(c(R1_RT$Latency, R2_RT$Latency, R1_No$Latency, R2_No$Latency))
maxTime <- length(R1_RT$Latency)
# Save our graph
png("graph.png")
# Start a plot with x- and y-axis labels and limitations
plot(0, 0, type="n", xlim=c(0,maxTime), ylim=c(0,maxLatency), xlab="Seconds", ylab="Latency", xaxt="n", yaxt="n")
# Draw y- and x-axis
yAxisMarks <- c(0, round(0.5*maxLatency), round(maxLatency))
xAxisMarks <- c(0, round(0.25*maxTime), round(0.5*maxTime), round(0.75*maxTime), maxTime)
axis(2, at=yAxisMarks)
axis(1, at=xAxisMarks)
# Draw lines for orientation
abline(h=yAxisMarks, col="gray", lwd=0.5)
# Colors
colors <- c("red2", "olivedrab4", "red4", "olivedrab2")
# Draw the 4 lines (functions)
lines(R2_No$Latency, col=colors[4])
lines(R1_No$Latency, col=colors[2])
lines(R2_RT$Latency, col=colors[3])
lines(R1_RT$Latency, col=colors[1])
# Legend
legend("topleft",inset=.05, title="Hardware 1",c("Normal","Realtime"),fill=c(colors[2],colors[1]))
legend("left",inset=.05,title="Hardware 2",c("Normal","Realtime"),fill=c(colors[4],colors[3]))
# Draw a box around the plot
box()
# Switch the device off to get a safe instance end
dev.off()
